package com.example.smartcity4.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartcity4.MainActivity;
import com.example.smartcity4.R;
import com.example.smartcity4.javaBean.GsonBean;

import java.util.List;

public class ListAdapter extends BaseAdapter {
    private List<GsonBean.Rows>rows;
    private Context context;

    public ListAdapter(List<GsonBean.Rows> rows, Context context) {
        this.rows = rows;
        this.context = context;
    }

    @Override
    public int getCount() {
        return rows.size();
    }

    @Override
    public Object getItem(int position) {
        return rows.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.list_item,parent,false);
        ImageView imageView=convertView.findViewById(R.id.image_list);
        TextView textView=convertView.findViewById(R.id.text1);
        TextView textView1=convertView.findViewById(R.id.text2);
        TextView textView2=convertView.findViewById(R.id.math);
        TextView textView3=convertView.findViewById(R.id.time);
        textView.setText(rows.get(position).title);
        textView1.setText(rows.get(position).content);
        textView2.setText("评论数:"+rows.get(position).commentNum);
        textView3.setText(rows.get(position).publishDate);
        Glide.with(context).load(MainActivity.host+rows.get(position).cover).into(imageView);
        return convertView;
    }
}
